// app.js
require('/utils/Page')

let $request = require('/utils/request')
wx.$request = $request
wx.get = $request.get
wx.baseURL = $request.baseURL
wx.put = $request.put
wx.post = $request.post
wx.delete = $request.delete
App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        console.log('I am wx.login',res)
        wx.get('http://localhost:3000/wxlogin/?code=' + res.code).then(res =>{
          wx.userInfo = res
          wx.token = res.token
          if(wx.waitLoginPages.length){
            for(let i = 0; i < wx.waitLoginPages.length;i++) {
              let page = wx.waitLoginPages[i]
              page.onLoad.call(page.context,page.options)
            }
          }
        })
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
  },
  globalData: {
    userInfo: null
  }
})
